<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <jducastel@jducastel.fr>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
* logs and benchmarking
* @author J.Ducastel <jducastel@jducastel.fr>
* @version 
*/
class wakBenchmark extends wakService {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access
	* /
	function wakBenchmark() {
		$this->__construct();
	}/**/
	
	/**
	* "real" constructor
	* @access
	* /
	function __construct() {
		//parent::__construct();
		// building log node
		wakapi::needclass('w3clognode');
		$this->log=&new w3clognode('data.store/logs/benchmark');
		echo wakapi::vardump($this);
		// autosaving logs
		//register_shutdown_function(array($this, '__destruct'));
	}/**/
	
	/**
	* destructor
	* @access
	* /
	function __destruct() {
		// saving log
		//echo '<p>toto</p>';
		$this->log->setFields(array_keys($this->timeflags));
		$this->log->writeLine($this->timeflags);
		echo wakapi::vardump($this);
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* sets time for a time-flag into a log
	* @param string $flag flag name
	* @access public
	* @return bool
	*/
	function timeFlag($log_name,$flag) {
		$this->timeflags[$log_name][$flag]=wak::timeCounter();
		$log=&$this->getlog($log_name);
		$log->addField($flag);
		return true;
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	*/
	function saveLogs() {
		foreach (array_keys($this->logs) as $name) {
			$this->logs[$name]->writeLine($this->timeflags[$name]);
		}
		return true;
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var w3cLogNode
	*/
	var $logs;
	/**
	* @var array time-flags flag=>time
	*/
	var $timeflags=array();
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access private
	* @return w3clognode
	*/
	function & getLog($name) {
		if (!isset($this->logs[$name])) {
			wakapi::needclass('w3clognode');
			$this->logs[$name]=&new w3clognode('data.store/logs/benchmark.'.$name);
		}
		return $this->logs[$name];
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
